package com.ruoyi.web.controller.tourism;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Spots;
import com.ruoyi.system.service.ISpotsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景点Controller
 *
 * @author Y.C
 * @date 2024-02-21
 */
@Api(tags = "景点管理")
@RestController
@RequestMapping("/system/spots")
public class SpotsController extends BaseController
{
    @Autowired
    private ISpotsService spotsService;

    /**
     * 查询景点列表
     */
    @ApiOperation("查询景点列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Spots spots)
    {
        startPage();
        List<Spots> list = spotsService.selectSpotsList(spots);
        return getDataTable(list);
    }

    /**
     * 导出景点列表
     */
    @Anonymous
    @ApiOperation("导出景点列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Spots spots)
    {
        List<Spots> list = spotsService.selectSpotsList(spots);
        ExcelUtil<Spots> util = new ExcelUtil<Spots>(Spots.class);
        util.exportExcel(response, list, "景点数据");
    }

    /**
     * 获取景点详细信息
     */
    @ApiOperation("获取景点详细信息")
    @Anonymous
    @GetMapping(value = "/{spotId}")
    public AjaxResult getInfo(@PathVariable("spotId") Long spotId)
    {
        return success(spotsService.selectSpotsBySpotId(spotId));
    }

    /**
     * 新增景点
     */
    @Anonymous
    @ApiOperation("新增景点")
    @PostMapping
    public AjaxResult add(@RequestBody Spots spots)
    {
        return toAjax(spotsService.save(spots));
    }

    /**
     * 修改景点
     */
    @Anonymous
    @ApiOperation("修改景点")
    @PutMapping
    public AjaxResult edit(@RequestBody Spots spots)
    {
        return toAjax(spotsService.updateById(spots));
    }

    /**
     * 删除景点
     */
    @Anonymous
    @ApiOperation("删除景点")
	@DeleteMapping("/{spotIds}")
    public AjaxResult remove(@PathVariable Long[] spotIds)
    {
        return toAjax(spotsService.removeByIds(Arrays.asList(spotIds)));
    }
    /**
     * 查询酒店spot_id和spot_name
     * */
    @ApiOperation("查询景点spot_id和spot_name")
    @Anonymous
    @GetMapping("/selectSpotIdAndName")
    public AjaxResult selectSpots()
    {

        return AjaxResult.success(spotsService.selectSpots());
    }

}
